| Conditions | 1 |
| Paths | 1 |
| Total Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 20 | var makeTipit = function( target ) {
|
||
| 21 | |||
| 22 | var showTipit = function( e ) {
|
||
|
|
|||
| 23 | |||
| 24 | var placementIndex = placements.indexOf( $target.attr( 'data-tipit-placement' ) ), |
||
| 25 | placement = placementIndex >= 0 ? placements[ placementIndex ] : placements[ 0 ], |
||
| 26 | |||
| 27 | // 'tipit' LM now has the same content as value of 'data-tipit-content' attribute then fill the variable **content** with it |
||
| 28 | content = $tipit.html( $target.attr( 'data-tipit-content' ) ) && $tipit.html(), |
||
| 29 | |||
| 30 | extraClassName = $target.attr( 'data-tipit-class' ), |
||
| 31 | |||
| 32 | offset = $target.offset(), |
||
| 33 | |||
| 34 | width = $target.outerWidth( false ), |
||
| 35 | height = $target.outerHeight( false ), |
||
| 36 | |||
| 37 | tipitWidth = $tipit.outerWidth( false ), |
||
| 38 | tipitHeight = $tipit.outerHeight( false ), |
||
| 39 | |||
| 40 | horiz = [ 'left', 'right' ].indexOf( placement ) >= 0, |
||
| 41 | far = [ 'right', 'bottom' ].indexOf( placement ) >= 0, |
||
| 42 | |||
| 43 | pos = {
|
||
| 44 | |||
| 45 | left: horiz ? |
||
| 46 | ( far ? offset.left + width + BORDER_WIDTH : offset.left - tipitWidth - BORDER_WIDTH ) : |
||
| 47 | ( offset.left + ( width / 2 ) - ( tipitWidth / 2 ) ), |
||
| 48 | |||
| 49 | top: horiz ? |
||
| 50 | ( offset.top + ( height / 2 ) - ( tipitHeight / 2 ) ) : |
||
| 51 | ( far ? offset.top + height + BORDER_WIDTH : offset.top - tipitHeight - BORDER_WIDTH ) |
||
| 52 | |||
| 53 | }; |
||
| 54 | |||
| 55 | if ( $tipit.data( 'timeout.id' ) ) |
||
| 56 | clearTimeout( $tipit.data( 'timeout.id' ) ); |
||
| 57 | |||
| 58 | if ( !content ) |
||
| 59 | return false; |
||
| 60 | |||
| 61 | $tipit.addClass( 'fx ' + placement + ( extraClassName ? ' ' + extraClassName : '' ) ); |
||
| 62 | |||
| 63 | $tipit.css({
|
||
| 64 | |||
| 65 | left: pos.left.toFixed( 2 ) + 'px', |
||
| 66 | top: pos.top.toFixed( 2 ) + 'px' |
||
| 67 | |||
| 68 | }); |
||
| 69 | |||
| 70 | }, |
||
| 71 | |||
| 72 | hideTipit = function( e ) {
|
||
| 73 | |||
| 74 | $tipit.removeClass( 'fx' ); |
||
| 75 | |||
| 76 | }, |
||
| 77 | |||
| 78 | hideTipitFn = function( e ) {
|
||
| 79 | |||
| 80 | var id = setTimeout( hideTipit, 150 ); |
||
| 81 | |||
| 82 | $tipit.data( 'timeout.id', id ); |
||
| 83 | |||
| 84 | }, |
||
| 85 | |||
| 86 | // We should append it as soon as we can, to make getting 'tipit's width possible |
||
| 87 | tipit = $( 'body' )[ 0 ].appendChild( d.createElement( 'div' ) ), |
||
| 88 | |||
| 89 | // Also we need to apply styles on it to returns the correct width |
||
| 90 | $tipit = $( tipit ).addClass( 'tipit' ), |
||
| 91 | |||
| 92 | $target = $( target ); |
||
| 93 | |||
| 94 | $( [ target, tipit ] ).on( 'mouseout', hideTipitFn ).on( 'mouseover', showTipit ); |
||
| 95 | |||
| 96 | target.showTipit = showTipit; |
||
| 97 | target.hideTipit = hideTipit; |
||
| 98 | |||
| 99 | }, |
||
| 100 | |||
| 129 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.